using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using FutureOpen.Web.Pages;
using FutureOpen.Core.func.sql;
using FutureOpen.Core.func.util;

public partial class controls_OverviewGroupsList : System.Web.UI.UserControl
{
    private int ctype;
    private int cid;
    private PageBase pbase;
    protected void Page_Load(object sender, EventArgs e)
    {
        pbase = (PageBase)this.Page;
        pbase.PageInit();
        ctype = pbase.typeid;
        cid = pbase.catid;

        cid = pbase.catid;
        if (!Page.IsPostBack)
        {
            BindGroup(0, 20);           
        }
    }
        
    public void BindGroup(int start, int end)
    {
        if (ctype == 2)
        {
            BuildGroups("group_art_count", start, end);
            this.lbArt.Enabled = false;
            this.lbRecent.Enabled = true;
            this.lbUsers.Enabled = true;
        }
        else if (ctype == 3)
        {
            BuildGroups("group_person_count", start, end);
            this.lbArt.Enabled = true;
            this.lbRecent.Enabled = true;
            this.lbUsers.Enabled = false;
        }
        else if (ctype == 4)
        {
            BuildGroups("group_creat_time", start, end);
        }
        else
        {
            ctype = 1;
            BuildGroups("group_last_time", start, end);
            this.lbArt.Enabled = true;
            this.lbRecent.Enabled = false;
            this.lbUsers.Enabled = true;
        }

    }
    public void BuildGroups(string order, int start, int end)
    {

        DataSet grps = GroupProvider.GetGroupByCat(cid, start, end, order);
        this.DataList1.DataSource = grps.Tables[0];
        this.DataList1.DataBind();        
    }

    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        BindGroup((e.NewPageIndex - 1) * 20, 20);
    }

    public string GetGroupName(object obj1, object obj2)
    {
        string url = "GroupView.aspx?"+pbase.GetParams()+"orgid="+obj1;
        return StringUtil.EncodeURL(url, obj2.ToString(), "_self"); 
    }

    protected void lbRecent_Click(object sender, EventArgs e)
    {
        pbase.typeid = 1;
        Response.Redirect("GroupView.aspx?" + pbase.GetParams());

    }
    protected void lbUsers_Click(object sender, EventArgs e)
    {

        pbase.typeid = 2;
        Response.Redirect("GroupView.aspx?" + pbase.GetParams());

    }
    protected void lbArt_Click(object sender, EventArgs e)
    {

        pbase.typeid = 3;
        Response.Redirect("GroupView.aspx?" + pbase.GetParams());

    }
}